/*
 * MyRadioButtonSpecialInfo.java
 *
 * Created on June 1, 2006, 11:31 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
import java.util.*;
import javax.swing.*;
/**
 *
 * @author Timoz
 */
public class MyRadioButtonSpecialInfo {
    
    private MyRadioButtonContainer myRadioButton;
    private Vector infoVector = new Vector ();
    private String tableName;
    
    /** Creates a new instance of MyRadioButtonSpecialInfo */
    public MyRadioButtonSpecialInfo(MyRadioButtonContainer myRadioButton, String tableName) {
        this.myRadioButton = myRadioButton;
        this.tableName = tableName;
        HandleCompRelation();
    }
    
     /**
     *  This function is used to get the info and save it
     */
     public void getAndSave () {
         myRadioButton.setRelation((String)(((JComboBox)infoVector.elementAt(1)).getSelectedItem()));
         //System.out.println("   is   "+(String)(((JComboBox)infoVector.elementAt(1)).getSelectedItem()));
     }
     
     /**
     * This Function is used to retrieve the info specific for the JButton
     * By applying some methods used to get those info
     */
    public Vector getInfoVector () {
        return infoVector;
    }
    
     //**************************************************************************
    /**
     *This function get text on the component
     */
    private void HandleCompRelation () {
        int selectIndex=0;
        Vector fieldsName;
        String relationOnRadioButton = myRadioButton.getRelation();
        if (relationOnRadioButton == null) {
            relationOnRadioButton =" ";
        }
        JLabel compText = new JLabel ("Relation on checkBox :");
        infoVector.addElement(compText);
        JComboBox tableFields = new JComboBox(); /*comboBox that has all the */
        tableFields.addItem(" ");
        MainWindow.dbCon.setDatabase((String)MainWindow.dbCon.getDatabases().elementAt(0));
        //tableName= (String)MainWindow.dbCon.getTables().elementAt(0);
        fieldsName = MainWindow.dbCon.getFields(tableName);
        //MyDB_InfoLoader fields = new MyDB_InfoLoader ();
        //fieldsName = fields.getDB_Info();
        //fieldsName=fields.getDB_Info((String)(fields.getDB_Info((String)(fields.getDB_Info().elementAt(0))).elementAt(0)));
        for (int i=0; i<fieldsName.size() ;i++ ) {
            tableFields.addItem(tableName+"."+(String)fieldsName.elementAt(i));
            if ( relationOnRadioButton.equals(tableName+"."+(String)fieldsName.elementAt(i) )) {
                selectIndex=i+1;
            }
        }   
        tableFields.setSelectedIndex(selectIndex);
        infoVector.addElement(tableFields);
        
   }
    
}
